<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="微信openId" prop="wxOpenId">
      <el-input v-model="dataForm.wxOpenId" placeholder="微信openId"></el-input>
    </el-form-item>
    <el-form-item label="昵称" prop="nickname">
      <el-input v-model="dataForm.nickname" placeholder="昵称"></el-input>
    </el-form-item>
    <el-form-item label="头像" prop="avatarUrl">
      <el-input v-model="dataForm.avatarUrl" placeholder="头像"></el-input>
    </el-form-item>
    <el-form-item label="电话" prop="phone">
      <el-input v-model="dataForm.phone" placeholder="电话"></el-input>
    </el-form-item>
    <el-form-item label="姓名" prop="name">
      <el-input v-model="dataForm.name" placeholder="姓名"></el-input>
    </el-form-item>
    <el-form-item label="性别 1:男 2：女" prop="gender">
      <el-input v-model="dataForm.gender" placeholder="性别 1:男 2：女"></el-input>
    </el-form-item>
    <el-form-item label="生日" prop="birthday">
      <el-input v-model="dataForm.birthday" placeholder="生日"></el-input>
    </el-form-item>
    <el-form-item label="身份证号码" prop="idcardNo">
      <el-input v-model="dataForm.idcardNo" placeholder="身份证号码"></el-input>
    </el-form-item>
    <el-form-item label="身份证地址" prop="idcardAddress">
      <el-input v-model="dataForm.idcardAddress" placeholder="身份证地址"></el-input>
    </el-form-item>
    <el-form-item label="身份证有效期" prop="idcardExpire">
      <el-input v-model="dataForm.idcardExpire" placeholder="身份证有效期"></el-input>
    </el-form-item>
    <el-form-item label="身份证正面" prop="idcardFrontUrl">
      <el-input v-model="dataForm.idcardFrontUrl" placeholder="身份证正面"></el-input>
    </el-form-item>
    <el-form-item label="身份证背面" prop="idcardBackUrl">
      <el-input v-model="dataForm.idcardBackUrl" placeholder="身份证背面"></el-input>
    </el-form-item>
    <el-form-item label="手持身份证" prop="idcardHandUrl">
      <el-input v-model="dataForm.idcardHandUrl" placeholder="手持身份证"></el-input>
    </el-form-item>
    <el-form-item label="准驾车型" prop="driverLicenseClass">
      <el-input v-model="dataForm.driverLicenseClass" placeholder="准驾车型"></el-input>
    </el-form-item>
    <el-form-item label="驾驶证证件号" prop="driverLicenseNo">
      <el-input v-model="dataForm.driverLicenseNo" placeholder="驾驶证证件号"></el-input>
    </el-form-item>
    <el-form-item label="驾驶证有效期" prop="driverLicenseExpire">
      <el-input v-model="dataForm.driverLicenseExpire" placeholder="驾驶证有效期"></el-input>
    </el-form-item>
    <el-form-item label="驾驶证初次领证日期" prop="driverLicenseIssueDate">
      <el-input v-model="dataForm.driverLicenseIssueDate" placeholder="驾驶证初次领证日期"></el-input>
    </el-form-item>
    <el-form-item label="驾驶证正面" prop="driverLicenseFrontUrl">
      <el-input v-model="dataForm.driverLicenseFrontUrl" placeholder="驾驶证正面"></el-input>
    </el-form-item>
    <el-form-item label="行驶证副页正面" prop="driverLicenseBackUrl">
      <el-input v-model="dataForm.driverLicenseBackUrl" placeholder="行驶证副页正面"></el-input>
    </el-form-item>
    <el-form-item label="手持驾驶证" prop="driverLicenseHandUrl">
      <el-input v-model="dataForm.driverLicenseHandUrl" placeholder="手持驾驶证"></el-input>
    </el-form-item>
    <el-form-item label="紧急联系人" prop="contactName">
      <el-input v-model="dataForm.contactName" placeholder="紧急联系人"></el-input>
    </el-form-item>
    <el-form-item label="紧急联系人电话" prop="contactPhone">
      <el-input v-model="dataForm.contactPhone" placeholder="紧急联系人电话"></el-input>
    </el-form-item>
    <el-form-item label="紧急联系人关系" prop="contactRelationship">
      <el-input v-model="dataForm.contactRelationship" placeholder="紧急联系人关系"></el-input>
    </el-form-item>
    <el-form-item label="腾讯云人脸模型id" prop="faceModelId">
      <el-input v-model="dataForm.faceModelId" placeholder="腾讯云人脸模型id"></el-input>
    </el-form-item>
    <el-form-item label="司机工号" prop="jobNo">
      <el-input v-model="dataForm.jobNo" placeholder="司机工号"></el-input>
    </el-form-item>
    <el-form-item label="评分" prop="score">
      <el-input v-model="dataForm.score" placeholder="评分"></el-input>
    </el-form-item>
    <el-form-item label="订单量统计" prop="orderCount">
      <el-input v-model="dataForm.orderCount" placeholder="订单量统计"></el-input>
    </el-form-item>
    <el-form-item label="认证状态 0:未认证  1：审核中 2：认证通过 -1：认证未通过" prop="authStatus">
      <el-input v-model="dataForm.authStatus" placeholder="认证状态 0:未认证  1：审核中 2：认证通过 -1：认证未通过"></el-input>
    </el-form-item>
    <el-form-item label="状态，1正常，2禁用" prop="status">
      <el-input v-model="dataForm.status" placeholder="状态，1正常，2禁用"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="修改时间" prop="updateTime">
      
<el-input v-model="dataForm.updateTime" placeholder="修改時間"></el-input>
    </el-form-item>
    <el-form-item label="是否刪除" prop="isDeleted">      <el-input v-model="dataForm.isDeleted" placeholder="是否刪除"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          wxOpenId: '',
          nickname: '',
          avatarUrl: '',
          phone: '',
          name: '',
          gender: '',
          birthday: '',
          idcardNo: '',
          idcardAddress: '',
          idcardExpire: '',
          idcardFrontUrl: '',
          idcardBackUrl: '',
          idcardHandUrl: '',
          driverLicenseClass: '',
          driverLicenseNo: '',
          driverLicenseExpire: '',
          driverLicenseIssueDate: '',
          driverLicenseFrontUrl: '',
          driverLicenseBackUrl: '',
          driverLicenseHandUrl: '',
          contactName: '',
          contactPhone: '',
          contactRelationship: '',
          faceModelId: '',
          jobNo: '',
          score: '',
          orderCount: '',
          authStatus: '',
          status: '',
          createTime: '',
          updateTime: '',
          isDeleted: ''
        },
        dataRule: {
          wxOpenId: [
            { required: true, message: '微信openId不能为空', trigger: 'blur' }
          ],
          nickname: [
            { required: true, message: '昵称不能为空', trigger: 'blur' }
          ],
          avatarUrl: [
            { required: true, message: '头像不能为空', trigger: 'blur' }
          ],
          phone: [
            { required: true, message: '电话不能为空', trigger: 'blur' }
          ],
          name: [
            { required: true, message: '姓名不能为空', trigger: 'blur' }
          ],
          gender: [
            { required: true, message: '性别 1:男 2：女不能为空', trigger: 'blur' }
          ],
          birthday: [
            { required: true, message: '生日不能为空', trigger: 'blur' }
          ],
          idcardNo: [
            { required: true, message: '身份证号码不能为空', trigger: 'blur' }
          ],
          idcardAddress: [
            { required: true, message: '身份证地址不能为空', trigger: 'blur' }
          ],
          idcardExpire: [
            { required: true, message: '身份证有效期不能为空', trigger: 'blur' }
          ],
          idcardFrontUrl: [
            { required: true, message: '身份证正面不能为空', trigger: 'blur' }
          ],
          idcardBackUrl: [
            { required: true, message: '身份证背面不能为空', trigger: 'blur' }
          ],
          idcardHandUrl: [
            { required: true, message: '手持身份证不能为空', trigger: 'blur' }
          ],
          driverLicenseClass: [
            { required: true, message: '准驾车型不能为空', trigger: 'blur' }
          ],
          driverLicenseNo: [
            { required: true, message: '驾驶证证件号不能为空', trigger: 'blur' }
          ],
          driverLicenseExpire: [
            { required: true, message: '驾驶证有效期不能为空', trigger: 'blur' }
          ],
          driverLicenseIssueDate: [
            { required: true, message: '驾驶证初次领证日期不能为空', trigger: 'blur' }
          ],
          driverLicenseFrontUrl: [
            { required: true, message: '驾驶证正面不能为空', trigger: 'blur' }
          ],
          driverLicenseBackUrl: [
            { required: true, message: '行驶证副页正面不能为空', trigger: 'blur' }
          ],
          driverLicenseHandUrl: [
            { required: true, message: '手持驾驶证不能为空', trigger: 'blur' }
          ],
          contactName: [
            { required: true, message: '紧急联系人不能为空', trigger: 'blur' }
          ],
          contactPhone: [
            { required: true, message: '紧急联系人电话不能为空', trigger: 'blur' }
          ],
          contactRelationship: [
            { required: true, message: '紧急联系人关系不能为空', trigger: 'blur' }
          ],
          faceModelId: [
            { required: true, message: '腾讯云人脸模型id不能为空', trigger: 'blur' }
          ],
          jobNo: [
            { required: true, message: '司机工号不能为空', trigger: 'blur' }
          ],
          score: [
            { required: true, message: '评分不能为空', trigger: 'blur' }
          ],
          orderCount: [
            { required: true, message: '订单量统计不能为空', trigger: 'blur' }
          ],
          authStatus: [
            { required: true, message: '认证状态 0:未认证  1：审核中 2：认证通过 -1：认证未通过不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '状态，1正常，2禁用不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/driver/driverinfo/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 200) {
                this.dataForm.wxOpenId = data.driverInfo.wxOpenId
                this.dataForm.nickname = data.driverInfo.nickname
                this.dataForm.avatarUrl = data.driverInfo.avatarUrl
                this.dataForm.phone = data.driverInfo.phone
                this.dataForm.name = data.driverInfo.name
                this.dataForm.gender = data.driverInfo.gender
                this.dataForm.birthday = data.driverInfo.birthday
                this.dataForm.idcardNo = data.driverInfo.idcardNo
                this.dataForm.idcardAddress = data.driverInfo.idcardAddress
                this.dataForm.idcardExpire = data.driverInfo.idcardExpire
                this.dataForm.idcardFrontUrl = data.driverInfo.idcardFrontUrl
                this.dataForm.idcardBackUrl = data.driverInfo.idcardBackUrl
                this.dataForm.idcardHandUrl = data.driverInfo.idcardHandUrl
                this.dataForm.driverLicenseClass = data.driverInfo.driverLicenseClass
                this.dataForm.driverLicenseNo = data.driverInfo.driverLicenseNo
                this.dataForm.driverLicenseExpire = data.driverInfo.driverLicenseExpire
                this.dataForm.driverLicenseIssueDate = data.driverInfo.driverLicenseIssueDate
                this.dataForm.driverLicenseFrontUrl = data.driverInfo.driverLicenseFrontUrl
                this.dataForm.driverLicenseBackUrl = data.driverInfo.driverLicenseBackUrl
                this.dataForm.driverLicenseHandUrl = data.driverInfo.driverLicenseHandUrl
                this.dataForm.contactName = data.driverInfo.contactName
                this.dataForm.contactPhone = data.driverInfo.contactPhone
                this.dataForm.contactRelationship = data.driverInfo.contactRelationship
                this.dataForm.faceModelId = data.driverInfo.faceModelId
                this.dataForm.jobNo = data.driverInfo.jobNo
                this.dataForm.score = data.driverInfo.score
                this.dataForm.orderCount = data.driverInfo.orderCount
                this.dataForm.authStatus = data.driverInfo.authStatus
                this.dataForm.status = data.driverInfo.status
                this.dataForm.createTime = data.driverInfo.createTime
                this.dataForm.updateTime = data.driverInfo.updateTime
                this.dataForm.isDeleted = data.driverInfo.isDeleted
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/driver/driverinfo/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'wxOpenId': this.dataForm.wxOpenId,
                'nickname': this.dataForm.nickname,
                'avatarUrl': this.dataForm.avatarUrl,
                'phone': this.dataForm.phone,
                'name': this.dataForm.name,
                'gender': this.dataForm.gender,
                'birthday': this.dataForm.birthday,
                'idcardNo': this.dataForm.idcardNo,
                'idcardAddress': this.dataForm.idcardAddress,
                'idcardExpire': this.dataForm.idcardExpire,
                'idcardFrontUrl': this.dataForm.idcardFrontUrl,
                'idcardBackUrl': this.dataForm.idcardBackUrl,
                'idcardHandUrl': this.dataForm.idcardHandUrl,
                'driverLicenseClass': this.dataForm.driverLicenseClass,
                'driverLicenseNo': this.dataForm.driverLicenseNo,
                'driverLicenseExpire': this.dataForm.driverLicenseExpire,
                'driverLicenseIssueDate': this.dataForm.driverLicenseIssueDate,
                'driverLicenseFrontUrl': this.dataForm.driverLicenseFrontUrl,
                'driverLicenseBackUrl': this.dataForm.driverLicenseBackUrl,
                'driverLicenseHandUrl': this.dataForm.driverLicenseHandUrl,
                'contactName': this.dataForm.contactName,
                'contactPhone': this.dataForm.contactPhone,
                'contactRelationship': this.dataForm.contactRelationship,
                'faceModelId': this.dataForm.faceModelId,
                'jobNo': this.dataForm.jobNo,
                'score': this.dataForm.score,
                'orderCount': this.dataForm.orderCount,
                'authStatus': this.dataForm.authStatus,
                'status': this.dataForm.status,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime,
                'isDeleted': this.dataForm.isDeleted
              })
            }).then(({data}) => {
              if (data && data.code === 200) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
